package edu.westga.movierec.controllers;

import edu.westga.movierec.model.*;
/**
 * Controller class that receives movie recommendations 
 * based on a user's choices.
 * 
 * @author jmcook
 *
 */
public class UserController {
	private XamppDBConnector theDatabase;
	/**
	 * Creates a new instance of the recommender interface 
	 * that will gets its data from a Xampp database
	 */
	public UserController(){
		theDatabase = new XamppDBConnector();
	}
	/**
	 * Returns a recommended movie based on the user's input
	 */
	public String getRecommendedMovie(int userID, String movieTitle){
		if(userID<=0){
			return "Invalid User";
		}
		else if(this.theDatabase.getMovieIndex(movieTitle)<=0){
			return "Invalid Movie";
		}
		return this.theDatabase.recommend(userID, movieTitle);
	}
	/**
	 * Processes a user's preference for a recommendation
	 * If the user liked it, increase rating, else decreases rating
	 */
	public void responseToRec(String input, String output, boolean preference){
		if(this.theDatabase.getMovieIndex(input)<=0 || this.theDatabase.getMovieIndex(output)<=0){
			return;
		}
		this.theDatabase.userResponse(input, output, preference);
	}
	/**
	 * Resets the user's history
	 */
	public void resetUser(int userID){
		this.theDatabase.resetUser(userID);
	}
}
